<?php
include ('chek.php');
//修改博客信息
$pid=$input->get('pid');
$is=array(
       'title'=>'',
        'aptor'=>'',
        'contact'=>''
);
 if($pid>0){
     $sql="select * from page WHERE pid='{$pid}'";
     $is=$db->query($sql)->fetch_array(MYSQLI_ASSOC);
 }

if($input->get('do')=='add'){
    $b_title=$input->post('b_title');
    $b_aptor=$input->post('b_aptor');
    $b_text=$input->post('b_text');
    if(empty($b_aptor) || empty($b_title)||empty($b_text)){
        die('标题或内容不能为空');
        exit;
    }
    //修改信息
    if($pid>0){
        $utime=time();
        $sql="update page set title='{$b_title}',aptor='{$b_aptor}',contact='{$b_text}',uptime='{$utime}' WHERE pid='{$pid}'";
    }
    //添加信息
    else{
        $intime=time();
        $sql="insert into page (title,aptor,contact,intime,uptime) VALUE ('{$b_title}','{$b_aptor}','{$b_text}','{$intime}','0')";
    }
    $result=$db->query($sql);
    if($result){
        header('location:blog.php');
    }
    else{
        die('执行失败！');
    }
}
?>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8" />
    <title>博客管理</title>
    <?php include (PATH.'/headr.php') ?>
    <link rel="stylesheet" href="../public/kindEditor/themes/default/default.css">
    <script type="text/javascript" src="../public/kindEditor/kindeditor-min.js"></script>
    <script type="text/javascript" src="../public/kindEditor/lang/zh_CN.js"></script>
    <script type="text/javascript">
        KindEditor.ready(function(K) {
            window.editor = K.create('#blog_add',{
                cssPath:'../public/kindEditor/plugins/code/prettify.css',
                uploadJson:'../public/kindEditor/php/upload_json.php',
                fileManagerJson:'../public/kindEditor/php/file_manager_json.php',
                resizeType :1,
                minHeight:300,
                allowPreviewEmoticons : true,
                allowImageUpload : true
            });
        });
    </script>
</head>
<body>
<?php include ('nac.inc.php'); ?>
<div class="container">
    <div class="row">
        <h2>管理员管理<small class="pull-right"><a class="btn btn-default" href="blog.php">返回</a></small></h2>
        <hr/>
        <form class="form-horizontal" action="blog_add.php?do=add&pid=<?php echo $pid?>" method="post">
            <div class="form-group">
                <label for="inputEmail3" class="col-sm-2 control-label">标题</label>
                <div class="col-sm-6">
                    <input type="text" name="b_title" class="form-control" id="inputEmail3" placeholder="请输入标题" value="<?php echo $is['title'] ?>">
                </div>
            </div>
            <div class="form-group">
                <label for="inputPassword3" class="col-sm-2 control-label">作者</label>
                <div class="col-sm-6">
                    <input type="text" name="b_aptor" class="form-control" id="inputPassword3" placeholder="请输入作者" value="<?php echo $is['aptor'] ?>" >
                </div>
            </div>
            <div class="form-group">
                <label for="inputPassword3" class="col-sm-2 control-label">内容</label>
                <div class="col-sm-6">
                    <textarea id="blog_add"  name="b_text" class="form-control"><?php echo $is['contact'] ?></textarea>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-6">
                    <button type="submit" class="btn btn-default">提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
</html>